<template>
	<view class="content">
		<view class="feedback-title">
			<view class="feedback-item">
				<view class="feedback-name">问题类型</view>
				<picker @change="bindPickerChange" :value="index" :range="opinionType" range-key="name">
					<view style="display: flex;align-items: center;">
						<view class="option-value">{{ opinionType[index].name }}</view>
						<view class="feedback-value-icon">
							<image style="width: 100%; height: 100%;" mode="aspectFit" :src="icons.right"></image>
						</view>
					</view>
				</picker>
			</view>
			<view class="feedback-item">
				<view class="feedback-name">联系人</view>
				<view class="feedback-value">
					<input v-model="linkman" placeholder="选填" />
				</view>
			</view>
			<view class="feedback-item">
				<view class="feedback-name">联系电话</view>
				<view class="feedback-value">
					<input v-model="linkman_mobile" placeholder="选填" />
				</view>
			</view>
		</view>
		<view class="feedback-content">
			<textarea v-model="content" class="feedback-textarea" placeholder-style="color:#B2B2B2" placeholder="感谢您留下宝贵意见及建议（10-200字）" />
			</view>
		<view class="upload-content">
			<view class="upload-img">
				<view class="add-icon">
					<image style="width: 100%; height: 100%;" mode="aspectFit" :src="icons.add"></image>
				</view>
			</view>
		</view>
		<view class="submit-content">
			<view class="submit-button" @click="submit">
				提交
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				icons: {
					right: '/static/images/icons/icon_next_button@3x .png',
					add: '/static/images/icons/icon_+@3x.png'
				},
				linkman:"",
				linkman_mobile:"",
				opinion_type: undefined,
				content: "",
				accessory: "",
				opinionType: [{name:'请选择', value: 1},{name:'系统问题反馈', value: 1}, {name:'商品问题反馈', value: 2}, {name:'流程问题反馈', value: 3},{name:'其他问题反馈', value: 4},{name:'我想吃', value: 5}],
				index: 0
			}
		},
		methods: {
			bindPickerChange(e){
				console.log('e', e.detail.value)
				this.index = e.target.value
			},
			submit(){
				if(!this.index){
					uni.showToast({
						icon: "none",
						title: '请选择反馈类型',
						duration: 2000
					});
					return false
				}
				const path = {
				    app:"wx",
				    api:"api_wx_user_feedback",
				    version:"1.0",
				    type:"2",
				    data:{
				        linkman: this.linkman || '',
				        linkman_mobile: this.linkman_mobile || '',
				        opinion_type: this.index,
				        content: this.content,
				        accessory:""
				    }
				}
				console.log('path', path)
				this.sendSock(path);
			},
			sendSock(path) {
				if (this.$store.state.socketOpen) {
					uni.sendSocketMessage({
						data: JSON.stringify(path)
					});
				} else {
					this.$store.state.socketMsgQueue.push(JSON.stringify(path));
				}
				const _this = this
				uni.onSocketMessage(function(res) {
					_this.getSock(res.data)
				});
			},
			getSock(res) {
				console.log('res', res)
				if (res !== '{"type":"ping"}') {
					const resj = JSON.parse(res);
					if (resj.code === -1) {
						uni.showToast({
							icon: "none",
							title: resj.message,
							duration: 2000
						});
					} else {
						if (resj.api === "api_wx_user_login") {
							this.$store.commit('login', resj.data);
							this.temporary()
						} else if (resj.api === "api_wx_user_keepLogin") {
							this.temporary()
						} else if (resj.api === "api_wx_user_feedback") {
							uni.showToast({
								icon: "none",
								title: '反馈成功',
								duration: 1000
							});
							const _this = this;
							setTimeout(()=>{
								uni.navigateTo({
									url: '/pages/personal/feedback/index?' + _this.version
								})
							},1000)
						} 
					}
				}
			}
		}
	}
</script>

<style>
	page {
		background-color: #F5F5F5;
	}

	.feedback-title {
		margin-top: 20rpx;
		background-color: #FFFFFF;
		padding: 0 30rpx;
	}
	
	.feedback-item{
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 100rpx;
	}
	.feedback-title .feedback-item:not(:last-child){
		border-bottom: 1px solid #E4E4E4;
	}
	.feedback-name{
		width: 120rpx;
		font-size:30rpx;
		font-family:PingFang SC;
		font-weight:500;
		color:rgba(51,51,51,1);
		line-height:1;
	}
	.feedback-value{
		flex: 1;
		text-align: right;
	}
	.feedback-value-icon{
		width: 30rpx;
		height: 15rpx;
		text-align: right;
		display: flex;
		align-items: center;
	}
		
	.feedback-content{
		margin-top: 20rpx;
		width: 100%;
		height:300rpx;
		padding: 30rpx;
		background:rgba(255,255,255,1);
		box-sizing: border-box;
	}
	.feedback-textarea{
		width: 100%;
		height: 100%;
	}
	
	.submit-content{
		width: 100%;
		position: fixed;
		bottom: 0;
		text-align: center;
	}   
	
	.submit-button{
		margin: auto;
		width:690rpx;
		height:98rpx;
		background:linear-gradient(0deg,rgba(255,195,36,1),rgba(255,211,94,1));
		box-shadow:0rpx 5rpx 5rpx 0rpx rgba(255,195,36,0.2);
		border-radius:49rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-size:32rpx;
		font-family:PingFang SC;
		font-weight:bold;
		color:rgba(51,51,51,1);
		line-height:1;
		margin-bottom: 90rpx;
	}
	
	.upload-content{
		display: flex;
		align-items: center;
	}
	
	.upload-content{
		margin-top: 30rpx;
	}
	
	.upload-img{
		width:180rpx;
		height:180rpx;
		background:rgba(255,255,255,1);
		border-radius:6rpx;
		margin: 0 30rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.add-icon{
		width: 36rpx;
		height: 36rpx;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.option-value{
		font-size:30rpx;
		font-family:PingFang SC;
		font-weight:500;
		color:rgba(153,153,153,1);
		line-height:1;
		margin-right: 10rpx;
	}
	
</style>
